import request from '@/utils/request'
import Qs from 'qs'

export default {
  /* 登录 */
  login: function({accountType, loginAccount, loginPassword}){
    return request({
      method: 'POST',
      url: '/auth/login',
      data: Qs.stringify({
        accountType: accountType,
        loginAccount: loginAccount,
        loginPassword: loginPassword
      })
    })
  },
  /* 获取用户信息 */
  memberInfo: function(id){
    return request({
      method: 'GET',
      url: '/member/'+id,
    })
  },
  /* 更新用户信息 */
  updateMemberInfo: function({id, nickname, headUrl}){
    return request({
      method: 'POST',
      url: '/member/updateMemberInfo',
      data: Qs.stringify({
        id: id,
        nickname: nickname,
        headUrl: headUrl
      })
    })
  },
  /* 获取用户附加信息 */
  memberAttachInfo: function(id){
    return request({
      method: 'GET',
      url: '/member/attach/'+id,
    })
  },
  /* 获取购物车列表 */
  cartList: function(id){
    return request({
      method: 'GET',
      url: '/member/memberCartList/'+id,
    })
  },
  /* 添加购物车 */
  addCart: function({goodsId, goodsNum, memberId}){
    return request({
      method: 'POST',
      url: '/member/addCart',
      data: Qs.stringify({
        goodsId: goodsId,
        goodsNum: goodsNum,
        memberId: memberId
      })
    })
  },
  /* 更新购物车 */
  updateCart: function({cartId , goodsNum}){
    return request({
      method: 'POST',
      url: '/member/updateCart',
      data: Qs.stringify({
        cartId: cartId,
        goodsNum: goodsNum
      })
    })
  },
  /* 删除购物车 */
  deleteCart: function({cartIds}){
    return request({
      method: 'POST',
      url: '/member/deleteCart',
      data: Qs.stringify({
        cartIds: cartIds
      })
    })
  },
  /* 获取收货地址列表 */
  addressList: function(id){
    return request({
      method: 'GET',
      url: '/member/addressList/'+id,
    })
  },
  /* 获取收货地址详情 */
  addressDetail: function(id){
    return request({
      method: 'GET',
      url: '/member/address/'+id,
    })
  },
  /* 添加收货地址 */
  addAddress: function({memberId, receiverName, phone, address, provinceId, provinceName, cityId, cityName, areaId, areaName, defaultFlag}){
    return request({
      method: 'POST',
      url: '/member/addAddress',
      data: Qs.stringify({
        memberId: memberId,
        receiverName: receiverName,
        phone: phone,
        address: address,
        provinceId: provinceId,
        provinceName: provinceName,
        cityId: cityId,
        cityName: cityName,
        areaId: areaId,
        areaName: areaName,
        defaultFlag: defaultFlag
      })
    })
  },
  /* 更新收货地址 */
  updateAddress: function({addressId, memberId, receiverName, phone, address, provinceId, provinceName, cityId, cityName, areaId, areaName, defaultFlag}){
    return request({
      method: 'POST',
      url: '/member/updateAddress',
      data: Qs.stringify({
        addressId: addressId,
        memberId: memberId,
        receiverName: receiverName,
        phone: phone,
        address: address,
        provinceId: provinceId,
        provinceName: provinceName,
        cityId: cityId,
        cityName: cityName,
        areaId: areaId,
        areaName: areaName,
        defaultFlag: defaultFlag
      })
    })
  },
  /* 删除收货地址 */
  deleteAddress: function({addressId}){
    return request({
      method: 'POST',
      url: '/member/deleteAddress',
      params: {
        addressId: addressId
      }
    })
  },
  /* 获取积分流水列表 */
  scoreList: function({memberId, status, pageNo, pageSize}){
    return request({
      method: 'GET',
      url: '/member/scoreList',
      params: {
        memberId: memberId,
        status: status,
        pageNo: pageNo,
        pageSize: pageSize
      }
    })
  },
  /* 查询某年某月签到记录 */
  dailySignList: function({memberId, year, month}){
    return request({
      method: 'GET',
      url: '/member/dailySignList?memberId='+memberId+"&year="+year+"&month="+month,
    })
  },
  /* 每日签到 */
  dailySign: function({memberId}){
    return request({
      method: 'POST',
      url: '/member/dailySign',
      data: Qs.stringify({
        memberId: memberId
      })
    })
  },
  /* 获取商品收藏列表 */
  goodsFavList: function({memberId, pageNo, pageSize}){
    return request({
      method: 'GET',
      url: '/member/goodsFavList',
      params: {
        memberId: memberId,
        pageNo: pageNo,
        pageSize: pageSize
      }
    })
  },
	/* 获取商品收藏状态 */
	goodsFavStatus: function({memberId, goodsId}){
	  return request({
	    method: 'GET',
	    url: '/member/goodsFavStatus?memberId='+memberId+"&goodsId="+goodsId
	  })
	},
  /* 商品收藏 */
  handleGoodsFav: function({memberId, goodsId, favStatus}){
    return request({
      method: 'POST',
      url: '/member/handleGoodsFav',
      data: Qs.stringify({
        memberId: memberId,
        goodsId: goodsId,
        favStatus: favStatus
      })
    })
  },
}
